<?php require_once('../../core/import.php');?>
<?php User::Permission('USER_UPDATE'); ?>
<?php
    if($_SERVER['REQUEST_METHOD']=='POST')
    {
		
		//exit($PassWords);
        #添加数据
		$UserName=Functions::FormArgs('Username');
		$Password=Functions::FormArgs('Password');
		$Password_Again=Functions::FormArgs('Password_Again');
		$ClassID=Functions::FormArgs('ClassID');
		$M_locked=Functions::FormArgs('M_locked');
		$is_i=Functions::FormArgs('is_i');
		$Modular=Functions::FormArgs('Modular');
		$Modulars='';
		$Functions='';
		if(count($Modular)>0){
			foreach($Modular as $Value){
				$Modulars.=$Value.',';	
			}
		}
		for($j=0;$j<$is_i;$j++){
			$Function=Functions::FormArgs('Function_'.$j);
			if(count($Function)>0){
				foreach($Function as $Value){
					$Functions.=$Value.',';	
				}
			}
		}
		$Permissions=$Modulars.$Functions;
		$Data=array();
		if($Password)
		{
			if($Password==$Password_Again) 
			{	
				$PassWord=User::EncryptPassword($Password,$UserName);
				$Data['Password']=$PassWord;
			}
			else
			{
				exit('{"Number":"2","Description":"重复输入密码错误！"}');	
			}
		}
		if($ClassID=='null')
		{
			$Data['Permissions']=$Permissions;
			$Data['RoleID']=null;
		}
		else
		{
			$Data['RoleID']=$ClassID;
		}
		$Data_Locked=DB::GetRows("select User from `management_user_locked` where User='$UserName'");
		if($Data_Locked)
		{
			$Locked=1;
		}
		else
		{
			$Locked=0;
		}
		if($M_locked!=$Locked) 
		{
			if($M_locked==1){
				DB::Insert('management_user_locked',array(
					'User'=>$UserName,
					'Datetime'=>date('Y-m-d G:i:s')
				));
			}else{
				DB::CExec("delete from management_user_locked where User='$UserName'");	
			}
		}
        DB::UpdateRowByID('management_user',Functions::FormArgs('ID'),$Data);
        echo '{"Number":"0","Description":"成功执行"}';
    }
?>